package pers.agony.controller;

import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.agony.constant.MessageConstant;
import pers.agony.entity.Result;
import pers.agony.service.UserService;

/**
 * @author : Agony
 * @date : Created in 8:17 下午 2021/11/5
 * @Description:
 * @Modified By:
 * @version: : 1.0
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/user/getUsername.do")
    public Result getUsername(){
        User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(user!=null) {
            return new Result(true, MessageConstant.GET_USERNAME_SUCCESS, user.getUsername());
        }else{
            return new Result(false, MessageConstant.GET_USERNAME_FAIL);
        }
    }
}
